import { getListApi, addListApi, deleListApi, updataListApi } from '../../api/classify'

const state = {
    tableData: []
}

const mutations = {
    GET_TABLEDATA(state, classify) {
        state.tableData = [{}, ...classify]
    }
}

const actions = {
    //渲染
    async getList({ commit }) {
        let r = await getListApi()
        commit('GET_TABLEDATA', r.data)
    },
    //新增
    async addList({ dispatch }, name) {
        await addListApi({ name })
        dispatch('getList')
    },
    //删除
    async deleList({ dispatch }, id) {
        await deleListApi({ id })
        dispatch('getList')
    },
    //修改
    async updataList({ dispatch }, row) {
        console.log(row);
        await updataListApi({ ...row })
        dispatch('getList')
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}